package com.menggudf.convert;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

import org.springframework.stereotype.Component;

import com.menggudf.entity.Illness;
import com.menggudf.entity.Symptom;
import com.menggudf.model.Illness2Model;
import com.menggudf.model.SymptomModel;

@Component
public class Illness2Convert {
    
    public Illness2Model entity2IllnessModelConvert(Illness ill){
        Illness2Model iModel = new Illness2Model();
        iModel.setId(ill.getId());
        iModel.setAuthor(ill.getAuthor());
        iModel.setCreateTime(ill.getCreateTime());
        iModel.setIllness(ill.getIllness());
        iModel.setLevelOneSubject(ill.getLevelOneSubject());
        iModel.setLevelTwoSubject(ill.getLevelTwoSubject());
        iModel.setModifyTime(ill.getModifyTime());
        iModel.setScheme(ill.getScheme());
        iModel.setPathogen(ill.getPathogen());
        iModel.setMedicine(ill.getMedicine());
        iModel.setDuration(ill.getDuration());
        String s = ill.getAssistantExam();
        List<String> ss = new ArrayList<String>();
        if(s.indexOf("\\s+|[，,]")==-1){
            ss = Arrays.asList(s.split("\\s+|[，,]"));
        }else{
            ss.add(s);
        }
        iModel.setAssistantExams(ss);
        List<SymptomModel> yModels = new ArrayList<SymptomModel>();
        Set<Symptom> tt = ill.getSymptoms();
        for(Symptom t :tt ){
            SymptomModel sModel = new SymptomModel();
            sModel.setSymptom(t.getSymptom());
            yModels.add(sModel);
        }
        iModel.setSymptoms(yModels);
        
/*        List<PartsModel> pModels = new ArrayList<PartsModel>();
        Set<Parts> pp = ill.getPartss();
        for(Parts p :pp ){
            PartsModel pModel = new PartsModel();
            pModel.setPart(p.getPart());
            pModels.add(pModel);
        }
        iModel.setPartss(pModels);*/
        
        return iModel;
        
    }

}
